package me.sluijsens.AntiEnderman;

import java.io.File;
import java.io.IOException;
import java.util.List;

import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration;

public class ConfigHandler {
	private File file;
	private FileConfiguration conf;

	public ConfigHandler(String nameFile, String dir, AntiEnderman instance) {
		// load the file
		file = new File(dir, nameFile + ".yml");
		conf = YamlConfiguration.loadConfiguration(file);
	}

	// set values
	public void set(String property, String value) {
		conf.set(property, value);
	}

	public void set(String property, boolean value) {
		conf.set(property, value);
	}

	public void set(String property, int value) {
		conf.set(property, value);
	}

	public void set(String property, long value) {
		conf.set(property, value);
	}

	public void set(String property, double value) {
		conf.set(property, value);
	}

	public void set(String property, List<?> value) {
		conf.set(property, value);
	}

	// get values
	public String getString(String property) {
		return conf.getString(property);
	}

	public String getString(String property, String value) {
		if (isSet(property))
			value = conf.getString(property);
		return value;
	}

	public boolean getBoolean(String property) {
		return conf.getBoolean(property);
	}

	public boolean getBoolean(String property, boolean value) {
		if (isSet(property))
			value = conf.getBoolean(property);
		return value;
	}

	public double getDouble(String property) {
		return conf.getDouble(property);
	}

	public double getDouble(String property, double value) {
		if (isSet(property))
			value = conf.getDouble(property);
		return value;
	}

	public long getLong(String property) {
		return conf.getLong(property);
	}

	public long getLong(String property, long value) {
		if (isSet(property))
			value = conf.getLong(property);
		return value;
	}

	public List<?> getList(String property) {
		return conf.getList(property);
	}

	public List<?> getList(String property, List<?> value) {
		if (isSet(property))
			value = conf.getList(property);
		return value;
	}

	public int getInt(String property) {
		return conf.getInt(property);
	}

	public int getInt(String property, int value) {
		if (isSet(property))
			value = conf.getInt(property);
		return value;
	}

	public Object get(String property) {
		return conf.get(property);
	}

	public Object getObject(String property, Object value) {
		if (isSet(property))
			value = conf.get(property);
		return value;
	}

	public boolean isSet(String property) {
		if (conf.isSet(property))
			return true;
		else
			return false;
	}

	public boolean exists() {
		if (file.exists())
			return true;
		else
			return false;
	}

	public boolean save() {
		// save file
		try {
			conf.save(file);
			return true;
		} catch (IOException e) {
			return false;
		}
	}
}
